<template>
	<div>
		<ul class="aui-list aui-form-list aui-margin-b-15">
			<li class="aui-list-item" v-if="false">
            	<div class="aui-list-item-inner" @click="goTomap">
                    <div class="aui-list-item-label">选择地区</div>
                    <div class="aui-list-item-input aui-list-item-arrow">
                        <div id="name" class="addressText" style="width: 100%;color: #757575;"> {{addressDetail?addressDetail:'如：北京市 市辖区 昭阳区'}} </div>
                    </div>
                </div>
            </li>
          
			<li class="aui-list-item menpai" @click="goTomap">
				<div class="aui-list-item-inner">
					<!--<div class="aui-list-item-label">详细地址</div>-->
					<div class="aui-list-item-label">收货地址</div>
					<div class="aui-list-item-input" style="text-align: left;">
						<p placeholder="如：圣城街道怡景小区5栋402" id="detail-address" >{{address?address:'选择地址信息'}}</p>
					</div>
				</div>
			</li>
			<li class="aui-list-item">
            	<div class="aui-list-item-inner">
                    <div class="aui-list-item-label">门牌号</div>
                    <div class="aui-list-item-input">				<!--houseNumber-->
						<input type="text" placeholder="门牌号码（选填）" v-model="houseNumber" id="addressHouseNumber" maxlength="10">
					</div>
                </div>
            </li>
		</ul>

	</div>
</template>

<script>
	
	import {mapActions,mapMutations} from 'vuex';
	import axios from 'axios';
	export default {
		props:{
			addFlag: {
				type: Boolean,
                default:true
			},
			getNowAddress: {
				type: Object,
				default: {}
			}
//			item: {
//              type: Object,
//              default:()=>{
//              	return {}
//              }
//          },
//          userInfomation: {
//          	type: Object,
//              default: ()=>{
//              	return {}
//              }
//          },
//          getstatusBtn: {
//          	type: Function,
//              default: () => {}
//          }
		},
		data() {
			return {
				address:'',
				addressDetail:null,
				province:null,
				city:null,
				region:null,
				obj:null,
				mapFlag:false,
				positionlat:null,
				positionlng:null,
				result:null,
				houseNumber:null // 门牌号
			}
		},
		watch:{
			province(nvalue,ovalue){
				let nowAddressSinger = {};
				nowAddressSinger.province = nvalue ;
				this.setNowAddressMutationSinger(nowAddressSinger);
//				console.log('provinceId',nvalue,ovalue);
			},
			city(nvalue,ovalue){
				let nowAddressSinger = {};
				nowAddressSinger.city = nvalue ;
				this.setNowAddressMutationSinger(nowAddressSinger);
//				console.log('cityId',nvalue,ovalue);
			},
			region(nvalue,ovalue){
				let nowAddressSinger = {};
				nowAddressSinger.region = nvalue ;
				this.setNowAddressMutationSinger(nowAddressSinger);
//				console.log('region',nvalue,ovalue);
			},
			address(nvalue,ovalue){
				let nowAddressSinger = {};
				nowAddressSinger.address = nvalue ;
				this.setNowAddressMutationSinger(nowAddressSinger);
//				console.log('addressDetail',nvalue,ovalue);
			},
			positionlng(nvalue,ovalue){
				let nowAddressSinger = {};
				nowAddressSinger.positionlng = nvalue ;
				this.setNowAddressMutationSinger(nowAddressSinger);
//				console.log('positionlng',nvalue,ovalue);
			},
			positionlat(nvalue,ovalue){
				let nowAddressSinger = {};
				nowAddressSinger.positionlat = nvalue ;
				this.setNowAddressMutationSinger(nowAddressSinger);
//				console.log('positionlat',nvalue,ovalue);
			},
			result(nvalue,ovalue){
//				console.log("添加详情.....",nvalue,ovalue)
				let nowAddressSinger = {};
				nowAddressSinger.result = nvalue ;
				this.setNowAddressMutationSinger(nowAddressSinger);
			},
			houseNumber(nvalue,ovalue){
				let nowAddressSinger = {};
				nowAddressSinger.houseNumber = nvalue ;
				this.setNowAddressMutationSinger(nowAddressSinger);
			}
		},
		methods:{
			...mapMutations('zx',[
				"setNowAddressMutationSinger",'setNowAddressMutation'
			]),
			...mapActions('zx',[
//				'addAddressQuicker'
			]),
			getAddressInfo(){
				let obj = this.$route.query;
				if(obj){
					console.log(obj.type,'555');
				}
				if(this.getNowAddress.result && !this.addFlag){
					let arr = this.getNowAddress.result.split(" ");
					this.addressDetail = arr[0]+' '+ arr[1]+ ' '+ arr[2];
					this.address = arr[3]
					console.log(arr,'arrarrarr');
					
				}
				
			},
//			getType(list) {
//	            let arr = []
//	            list && list.map((item) => {
//	                arr.push({text: item.name,value: item.id})
//	            })
//	            return arr
//	        },
			async getArea (code) {
//				var url = 'http://172.19.6.152:33001/address/select/'
//	            let res = await axios.get(window.api.mall_base_host + '/address/getarealist?areaid=' + code)
	            let res = await axios.get(window.api.base_host+'/address/select/' + code)
	            return res.data.data
	        },
	        goTomap(){
	        	if(this.addFlag){
	        		if(this.$route.query.toFrom){
	        			this.$router.push({path:'map',query:{type:'add',toFrom:'chooseAddress'}});
	        		}else if(this.$route.query.id != undefined){
	        			this.$router.push({path:'map',query:{type:'add',id:1}});
	        		}else{
	        			this.$router.push({path:'map',query:{type:'add'}});
	        		}
	        	}else{
	        		console.log(this.getNowAddress,'当前地址去');
	        		if(this.getNowAddress.positionlng || this.getNowAddress.positionlat){
	        			var positionlng = this.getNowAddress.positionlng;
	        			var positionlat = this.getNowAddress.positionlat;
	        		}
	        		if(this.$route.query.id != undefined){
	        			this.$router.push({path:'map',query:{id:1,type:'edit',positionlng:positionlng,positionlat:positionlat,addressDetail:this.addressDetail}});
	        		}else{
	        			this.$router.push({path:'map',query:{type:'edit',positionlng:positionlng,positionlat:positionlat,addressDetail:this.addressDetail}});
	        		}
	        	}
	        },
	        //初始化经纬度
	        innitPingLan(){
	        	var obj = this.getNowAddress;
	        	obj.positionlng = this.positionlng;
	        	obj.positionlat = this.positionlat;
	        	this.houseNumber = obj.houseNumber;
	        	this.setNowAddressMutation(obj);
	        },
	        getQuery(){
	        	console.log('进来看看')
	        	if(this.$route.query.obj != undefined){
	        		this.mapFlag = true;
	        		console.log(this.$route.query.obj,'快速編輯地址');
//	        		console.log(this.getNowAddress,'当前地址回');
	        		this.obj = JSON.parse(this.$route.query.obj);
	        		this.address = this.obj.address;
	        		this.addressDetail = this.obj.province + ' ' + this.obj.city + ' ' + this.obj.region;
	        		this.result = this.obj.province + ' ' + this.obj.city + ' ' + this.obj.region + " " + this.obj.address;
//	        		console.log(this.result,'详细地址++++')
	        		
	        		this.positionlng = this.obj.positionlng;
	        		this.positionlat = this.obj.positionlat;
	        		this.houseNumber = this.obj.houseNumber;
	        		console.log(this.obj,'編輯好事心中');
					this.addAddressQuicker(this.obj);
	        	}else{
	        		this.positionlng = this.getNowAddress.positionlng;
	        		this.positionlat = this.getNowAddress.positionlat;
	        	}
	        },
	        addAddressQuicker(obj){
	        	if(obj){
	        		var provinceId = null;
//	        		let url = window.api.mall_base_host + '/address/getarealist?areaid=' + 1   erp接口
					var url = window.api.base_host+'/address/select/'
//	        		http://172.19.5.89:33001/address/select/1 
			        axios.get(url + 1).then((res)=>{
			      
			        	var province = res.data.data;
			        	for(let i = 0; i < province.length; i++){
			        		console.log(obj.province,'obj.province')
			        		if(obj.province == province[i].name){
			        			console.log(province[i].id,'province[i].name')
			        			this.province = province[i].rid;
			        			axios.get(url + province[i].rid).then((res)=>{
			        				var city = res.data.data;
			        				for(let j = 0; j < city.length; j++){
			        					if(obj.city === city[j].name){
//			        						console.log(city[j].rid,'city[j].name');
			        						this.city = city[j].rid;
			        						axios.get(url + city[j].rid).then((res)=>{
			        							var region = res.data.data;
			        							for(let k = 0 ;k < region.length; k++){
			        								if(obj.region === region[k].name){
			        									this.region = region[k].rid;
			        								}
			        							}
			        						})
			        					}
			        				}
			        			})
			        		}
			        	}
			        })
	        	}
	        },
		},
		created(){
			this.getAddressInfo();
			this.getQuery();
			this.innitPingLan();
			
		},
		beforeCreate(){
	       
	    },
	    beforeDestroy(){
	       
	    },
	}
</script>

<style scoped="scoped">
	.addressText{
		text-align: left;
	}
	
</style>